<?xml version="1.0" encoding="UTF-8"?>

<!--
    Document   : data-dict-stype.xsl
    Created on : January 19, 2011, 9:58 AM
    Author     : ReutyCheng
    Description:
        Purpose of transformation follows.
-->

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
  <xsl:output method="html"/>

  <!-- TODO customize transformation rules
         syntax recommendation http://www.w3.org/TR/xslt
    -->
  <xsl:template match="/">
    <html>
      <head>
        <title>Data Dict</title>
        <style type="text/css">
          /* Common Style */
          html, body, p, table, td, h1, h2, h3, h4, h5, h6, input, button
          {
          padding: 0;
          margin: 0;
          border: none;
          font-family: Arial Unicode MS, Arial, sans-serif;
          font-size: 12pt;
          }
          body
          {
          padding: 5px;
          }
          h1
          {
          border-bottom: 1px solid #FBA1A1;
          font-size: 2.0em;
          margin-bottom: 5px;
          text-align: center;
          }
          table
          {
          border: none;
          border-spacing: 0;
          border-collapse: collapse;
          width: 100%;
          }
          tr
          {
          background: #FFFFFF;
          }
          th, td
          {
          padding: 0px 3px;
          line-height: 25px;
          }
          a
          {
          color: #A52F2F;
          font-weight: bold;
          }
          .copyright
          {
          border-top: 1px #FF0000 solid;
          color: #FF0000;
          font-style: italic;
          font-size: 10pt;
          margin: 10px 0px;
          text-align: right;
          }

          /* Specific Style */
          .data_dict
          {
          }
          .quick_search_container
          {
          margin-top: 5px;
          padding: 3px;
          background-color: #DAD3D3;
          }
          .quick_search_container input
          {
          border: 1px solid #000000;
          padding: 2px;
          }
          .db_table
          {
          background-color: #EFF3F6;
          border: 2px solid #E7EBED;
          margin-bottom: 10px;
          padding: 5px;
          }
          .table_info
          {
          margin-bottom: 5px;
          }
          .table_name
          {
          font-weight: bold;
          }
          .db_fields
          {
          border:1px solod #000000;
          }
          .field_name
          {
          width:300px;
          }
          .field_type_size
          {
          width:150px;
          }
          .undefined
          {
          color: #E84E4E;
          }
          .undefined_field
          {
          background-color: #F2D6D6;
          }
          .related_table_container
          {
          border: 1px solid #FBA1A1;
          margin-top: 5px;
          }
          .related_table_header
          {
          background-color: #FBA1A1;
          padding: 2px;
          }
          .related_table_content
          {
          background-color: #FFE5E5;
          padding: 5px 2px;
          }
          .related_table_link
          {
          margin: 0px 5px;
          }
        </style>
      </head>
      <body class="data_dict">
        <h1>Data Dict - OXFAMADM</h1>
        <xsl:for-each select="DataDict/Table">
          <xsl:element name="div">
            <xsl:attribute name="id"><xsl:value-of select="@name" /></xsl:attribute>
            <xsl:attribute name="class">db_table</xsl:attribute>
            <xsl:choose>
              <xsl:when test="@status='undefined'">
                <p class="table_info"><span class="table_name"><xsl:value-of select="@name" /></span> [<span class="table_disc"><xsl:value-of select="@disc" /></span>] (<span class="undefined">Undefined</span>)</p>
              </xsl:when>
              <xsl:otherwise>
                <p class="table_info"><span class="table_name"><xsl:value-of select="@name" /></span> [<span class="table_disc"><xsl:value-of select="@disc" /></span>]</p>
              </xsl:otherwise>
            </xsl:choose>
            <table class="db_fields">
              <thead>
                <tr style="background:#000000; color:#FFFFFF">
                  <th class="field_name">Field Name</th>
                  <th class="field_type_size">Field Type &amp; Size</th>
                  <th class="field_disc">Field Disc</th>
                </tr>
              </thead>
              <tbody>
                <xsl:for-each select="Field">
                  <xsl:choose>
                    <xsl:when test="@status='undefined'">
                      <tr class="undefined_field">
                        <td><xsl:value-of select="@name" /></td>
                        <td><xsl:value-of select="@type" /> (<xsl:value-of select="@size" />)</td>
                        <td><xsl:value-of select="@disc" /> (<span class="undefined">Undefined</span>)</td>
                      </tr>
                    </xsl:when>
                    <xsl:otherwise>
                      <tr class="">
                        <td><xsl:value-of select="@name" /></td>
                        <td><xsl:value-of select="@type" /> (<xsl:value-of select="@size" />)</td>
                        <td><xsl:value-of select="@disc" /></td>
                      </tr>
                    </xsl:otherwise>
                  </xsl:choose>
                </xsl:for-each>
              </tbody>
            </table>
            <xsl:if test="count(RelatedTable) != 0 ">
              <div class="related_table_container">
                <p class="related_table_header">Related Tables</p>
                <p class="related_table_content">
                  <xsl:for-each select="RelatedTable">
                    <span class="related_table_link">
                      <xsl:element name="a">
                        <xsl:attribute name="href">#<xsl:value-of select="@name" /></xsl:attribute>
                        <xsl:value-of select="@name" />
                      </xsl:element>
                    </span>
                  </xsl:for-each>
                </p>
              </div>
            </xsl:if>
            <div class="quick_search_container">
              <span>Go to Table : </span><input onkeydown="if (event.keyCode == 13) quickSearch(this.value);" /><!--<a onclick="quickSearch();">Quick Search</a>-->
            </div>
          </xsl:element>
        </xsl:for-each>
        <div class="copyright dom_bottom">By CES</div>
      </body>
      <script type="text/javascript">
        function quickSearch(tableName) {
          var inputElements = document.getElementsByTagName('input');
          for (var inputElement in inputElements) {
            inputElement.value = "";
          }
          
          document.location.href = '#' + tableName.toString().toUpperCase();
        }
      </script>
    </html>
  </xsl:template>
</xsl:stylesheet>
